package com.extremelylargepackage.entity;

import com.extremelylargepackage.GameResources;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.Log;

public class Shield extends Entity
{
	private Player _player;
	private final int FADE_TIME = 500;
	private int _timeVisible;
	private Paint _paint;
	private boolean _visible;
	private boolean _invincible;
	
	public Shield(Player player)
	{
		_sprite = GameResources.getResource("shield");
		_player = player;
		_timeVisible = 0;
		_visible = false;
		_paint = new Paint();
	}
	
	@Override
	public void updateState(long time) 
	{
		if(_visible && !_invincible)
		{
			_timeVisible += time;
			if(_timeVisible >= FADE_TIME)
				_visible = false;
		}
	}
	
	public void activate(boolean invincible)
	{
		_visible = true;
		_timeVisible = 0;
		_invincible = invincible;
	}
	
	public boolean isVisible()
	{
		return _visible;
	}
	
	public boolean isInvincible()
	{
		return _invincible;
	}

	@Override
	public void onCollision(Entity z) 
	{
		//nothing
	}

	@Override
	public void draw(Canvas c) 
	{
		float percent = (_timeVisible)/(float)FADE_TIME;
		_paint.setAlpha((int)(255 - (percent * 255)));
		c.drawBitmap(_sprite.getBitmap(), 
				_player.getLocX() + ((_player.getWidth() -_sprite.getWidth())/2),
				_player.getLocY() + ((_player.getHeight() -_sprite.getHeight())/2),
				_paint);
	}

}
